package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.hjq.http.EasyHttp
import com.hjq.http.listener.OnHttpListener
import com.ht.medicaltreatment.bean.CentrifugeParamsBean
import com.ht.medicaltreatment.http.api.CentrifugeInfoAPI
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class CentrifugeParamsViewModel : BaseViewModel(){
    fun changParams(map: MutableMap<String,String> ,onSuccess:()->Unit, onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.changeCentrifugeParams(map)
            when(bean){
                is ApiResult.Success -> onSuccess()
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    //根据id查询离心机信息
    fun requestInfo(id:String){
        EasyHttp.post(this)
            .api(CentrifugeInfoAPI(id))
            .request(object : OnHttpListener<CentrifugeParamsBean>{
                override fun onHttpSuccess(result: CentrifugeParamsBean?) {

                }

                override fun onHttpFail(e: Exception?) {
                }
            })
    }
}